//人员动态
function countryUserChart(data) {
  var chart = Highcharts.chart(
    "countryUser",
    {
      chart: {
        spacing: [40, 0, 40, 0],
      },
      colors: [
        "#5470c6", //第一个颜色，欢迎加入Highcharts学习交流群294191384
        "#91cc75", //第二个颜色
        "#fac858", //第三个颜色
        "#ee6666",
        "#73c0de",
        "#eee",
      ],
      title: {
        floating: true,
        text: "",
      },
      tooltip: {
        pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>",
      },
      plotOptions: {
        pie: {
          allowPointSelect: false,
          cursor: "pointer",
          dataLabels: {
            enabled: false,
            format: "",
            style: {
              color:
                (Highcharts.theme && Highcharts.theme.contrastTextColor) ||
                "black",
            },
          },
          point: {
            events: {
              mouseOver: function (e) {
                // 鼠标滑过时动态更新标题
                // 标题更新函数，API 地址：https://api.hcharts.cn/highcharts#Chart.setTitle
                chart.setTitle({
                  // text: e.target.name+ '\t'+ e.target.y + ' %'
                });
              },
            },
          },
        },
      },
      series: [
        {
          type: "pie",
          innerSize: "60%",
          name: "",
          data: data?.map((item) => {
            return {
              name: item.title,
              y: item.count,
            };
          }),
          //   [
          //   ["HOUSTON,TX", 71.04],
          //   ["HOUSTON, HOUSTON, TEXAS", 14.76],
          //   ["PORT EVERGLADES,FL", 7.11],
          //   ["NEW YORK/NEWARK AREA, NEWARK, NEW JERSEY", 2.19],
          //   ["PORT OF ENTRY-PORT EVERGLADES/FORT LAUDERDALE, POR", 2.19],
          //   ["no name", 11.44],
          // ],
        },
      ],
    },
    function (c) {
      // 图表初始化完毕后的会掉函数
      // 环形图圆心
      var centerY = c.series[0].center[1],
        titleHeight = parseInt(c.title.styles.fontSize);
      // 动态设置标题位置
      c.setTitle({
        y: centerY + titleHeight / 2,
      });
    }
  );
}

//总数
function totalFunc(dateList, list) {
  var chart = Highcharts.chart("sumChart", {
    chart: {
      type: "column",
    },
    colors: [
      "#5470c6", //第一个颜色，欢迎加入Highcharts学习交流群294191384
      "#91cc75", //第二个颜色
      "#fac858", //第三个颜色
      "#ee6666",
      "#73c0de",
      "#eee",
      "#5470c0", //第一个颜色，欢迎加入Highcharts学习交流群294191384
      "#91cc68", //第二个颜色
      "#fac723", //第三个颜色
      "#ee22222",
      "#52c0de",
      "#12c0de",
    ],
    title: {
      text: "",
    },
    xAxis: {
      categories: dateList,
    },
    yAxis: {
      min: 0,
      title: {
        text: "",
      },
    },
    exporting: {
      enabled: false,
    },
    credits: {
      enabled: false,
    },
    legend: {
      align: "right",
      x: -30,
      verticalAlign: "top",
      y: 25,
      floating: true,
      backgroundColor:
        (Highcharts.theme && Highcharts.theme.background2) || "white",
      borderColor: "#CCC",
      borderWidth: 1,
      shadow: false,
    },
    tooltip: {
      pointFormat:
        '<span style="{series.color}">{series.name}</span>: <b>{point.y}</b>' +
        "<br/>",
      shared: true,
    },
    plotOptions: {
      column: {
        stacking: "normal",
      },
    },
    series: list?.map((item) => {
      return {
        name: item.name,
        data: item.data.map(Number),
      };
    }),
    // [
    //   {
    //     name: "unknown",
    //     data: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
    //   },
    //   {
    //     name: "humen_resources",
    //     data: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    //   },
    // ],
  });
}

//保留
function retainFunc(dateList, list) {
  var chart = Highcharts.chart("holdChart", {
    chart: {
      type: "column",
    },
    colors: [
      "#5470c6", //第一个颜色，欢迎加入Highcharts学习交流群294191384
      "#91cc75", //第二个颜色
      "#fac858", //第三个颜色
      "#ee6666",
      "#73c0de",
      "#eee",
    ],
    title: {
      text: "",
    },
    xAxis: {
      categories: dateList,
      //   [
      //   "2022-09-01",
      //   "2022-10-01",
      //   "2022-11-01",
      //   "2022-12-01",
      //   "2023-01-01",
      //   "2023-02-01",
      //   "2023-03-01",
      //   "2023-04-01",
      //   "2023-05-01",
      //   "2023-06-01",
      // ],
    },
    yAxis: {
      min: 0,
      title: {
        text: "",
      },
    },
    exporting: {
      enabled: false,
    },
    credits: {
      enabled: false,
    },
    legend: {
      align: "right",
      x: -30,
      verticalAlign: "top",
      y: 25,
      floating: true,
      backgroundColor:
        (Highcharts.theme && Highcharts.theme.background2) || "white",
      borderColor: "#CCC",
      borderWidth: 1,
      shadow: false,
    },
    tooltip: {
      pointFormat:
        '<span style="{series.color}">{series.name}</span>: <b>{point.y}</b>' +
        "<br/>",
      shared: true,
    },
    plotOptions: {
      column: {
        stacking: "normal",
      },
    },
    series: list,
    //   [
    //   {
    //     name: "新增",
    //     data: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
    //   },
    //   {
    //     name: "保留",
    //     data: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    //   },
    //   {
    //     name: "变动",
    //     data: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
    //   },
    // ],
  });
}
